import com.zkthink.ceres.generator.CodeGenerator;
import com.zkthink.ceres.generator.config.CodeGeneratorConfig;
import com.zkthink.ceres.generator.config.FileCreateConfig;
import com.zkthink.ceres.generator.type.EntityType;
import com.zkthink.ceres.generator.type.GenerateType;

import java.util.Arrays;
import java.util.List;

/**
 */
public class CommonGenerator {

    public static void main(String[] args) {
        CodeGeneratorConfig build = buildMemberEntity();

        // 下面是数据库的账号和密码
        build.setUsername("root");
        build.setPassword("123456");

        System.out.println("输出路径：");
        // 这里需要设置成你的项目所在的路径
        String outputPath = System.getProperty("user.dir") + "/ceres/ceres-product";
        System.out.println(outputPath);
        build.setProjectRootPath(outputPath);

        FileCreateConfig fileCreateConfig = new FileCreateConfig(GenerateType.OVERRIDE);
        build.setFileCreateConfig(fileCreateConfig);

        build.setProjectPrefix("cereshop");
        for (String module:CodeGeneratorConfig.CERESHOP_MODULAR_LIST) {
            build.setCurrentModule(module);
            CodeGenerator.run(build);
        }
    }


    private static CodeGeneratorConfig buildMemberEntity() {
        List<String> tables = Arrays.asList(
                "cere_generate_test"
        );
        //这一行不用改，第四个参数是表名称的前缀
        CodeGeneratorConfig build = CodeGeneratorConfig.
                build("", "", "", "cere", tables);
        //填写基础包
        build.setPackageBase("com.shop.cereshop");
        //填写子包名称
        build.setChildPackageName("live");
        //设置数据库url
        build.setUrl("jdbc:mysql://127.0.0.1:3306/cereshop1.6?serverTimezone=CTT&characterEncoding=utf8&useUnicode=true&useSSL=false&autoReconnect=true&zeroDateTimeBehavior=convertToNull");
        return build;
    }
}
